package com.silence.springboot.dao;


import com.mybatisflex.core.query.QueryWrapper;
import com.silence.springboot.entity.LoginStudentEntity;
import com.silence.springboot.mapper.LoginStudentMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import static com.silence.springboot.entity.table.LoginStudentEntityTableDef.LOGIN_STUDENT_ENTITY;

/**
 * @description 登录学生的Dao层
 * @className LoginStudentDao
 * @Author silence
 * @Date 2020/1/31 14:37
 * @Version 1.0
 **/
@Slf4j
@Repository
@RequiredArgsConstructor
public class LoginStudentDao {

    /**
     * 登录学生的Mapper层
     */
    private final LoginStudentMapper loginStudentMapper;

    /**
     * 根据用户名查询登录学生的信息
     *
     * @param username 用户名
     * @return 登录学生的信息
     */
    public LoginStudentEntity selectOneByQuery(String username) {
        // 查询数据库中的用户名和密码
        return loginStudentMapper.selectOneByQuery(QueryWrapper.create()
                .select()
                .from(LOGIN_STUDENT_ENTITY)
                .where(LOGIN_STUDENT_ENTITY.USERNAME.eq(username))
        );
    }
}
